package com.dongdongshop.mq;

import com.dongdongshop.service.ItemPageServiceI;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Component
// 配置消费者监听的topic和消费者的组
@RocketMQMessageListener(topic = "dongdongshop-itempage",consumerGroup = "dongdongshop")
public class ItemPageMQ implements RocketMQListener<Long[]> {
    @Autowired
    private ItemPageServiceI itemPageServiceI;

    @Override
    public void onMessage(Long[] ids) {
        try {
            for (Long id:ids){
                itemPageServiceI.createItemPage(id);
                System.out.println("消费成功");
            }

        }catch (Exception e){
            System.out.println("消费失败");
        }
    }
}


